package edu.gatech.cs2340.group7.wheresmystuffapp.presenters;

import edu.gatech.cs2340.group7.wheresmystuffapp.model.DataManager;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.ChangePasswordView;
/**
 * This does all the work for the change password screen
 * @author Sarah
 *
 */
public class ChangePasswordPresenter {
	private ChangePasswordView myView;

	public ChangePasswordPresenter(ChangePasswordView view) {
		myView = view;
	}

	/**
	 * Changes the password for the user
	 * 
	 * @param oldPassword
	 *            The old password for the current account
	 * @param newPassword
	 *            The new password for the current account
	 * @param newPasswordConfirm
	 */
	public void changePassword(String oldPassword, String newPassword,
			String newPasswordConfirm) {
		if (newPassword.equals(newPasswordConfirm) & !newPassword.isEmpty()) {
			String username = DataManager.getCurrentAccountName();
			DatabaseHelper myHelper = new DatabaseHelper(myView);
			boolean worked = myHelper.changeAccountPassword(username, oldPassword, newPassword);
			
			if (worked) {
				myView.setChangePasswordResult("Password Changed");
			} else {
				myView.setChangePasswordResult("Password Not Changed");
			}
		}
	}
}
